package com.atbun.statisticsservice.controller;


import com.atbun.commonutils.R;
import com.atbun.statisticsservice.service.StatisticsDailyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-05-22
 */
@RestController
@RequestMapping("/statisticsservice/sta")
public class StatisticsDailyController {

    @Autowired
    private StatisticsDailyService dailyService;

    /**
     * 统计每天注册人数，把数据添加到statistics_daily表中
     * @param day
     * @return
     */
    @PostMapping("registerCount/{day}")
    public R createStatisticsByDay(@PathVariable String day){
        dailyService.createStatisticsByDay(day);
        return R.ok();
    }

    /**
     * 根据前端的三个值进行生成统计图
     * @param begin 统计的开始时间
     * @param end 统计的结束时间
     * @param type 类型分为：学员登录数统计，学员注册数统计，课程播放数统计，每日课程数统计
     * @return
     */
    @GetMapping("showChart/{begin}/{end}/{type}")
    public R showChart(@PathVariable String begin,@PathVariable String end,@PathVariable String type){
        Map<String,Object> map = this.dailyService.showChart(begin,end,type);
        return R.ok().data(map);
    }
}

